package com.reason.oauth.controller;

import com.reason.common.exception.HWException;
import com.reason.common.pojo.Result;
import com.reason.common.pojo.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author
 * @date 2020/7/2 9:28 上午
 */
@ControllerAdvice //声明该类是一个异常类
public class ExceptionHandler {

    //对那些异常处理
    @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        if (e instanceof HWException) {
            HWException hw = (HWException) e;
            return hw.getResult();
        }
        e.printStackTrace();//打印异常
        return new Result(false, StatusCode.ERROR, "客官! 服务器正忙...");

    }

}
